package com.hy.study.reduce;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

/**
 * @author huyong
 * @date 2024 年 01 月 31 日 10:15: 46
 */
public class NLineWordCountReducer extends Reducer<Text, LongWritable, Text, LongWritable> {
    private LongWritable value = new LongWritable();

    @Override
    protected void reduce(Text key, Iterable<LongWritable> values, Reducer<Text, LongWritable, Text, LongWritable>.Context context) throws IOException, InterruptedException {
        long sum = 0;
        for (LongWritable value : values) {
            sum += value.get();
        }
        value.set(sum);
        context.write(key, value);
    }
}
